cd "${mystart}/Simulated data\Calibration/Benchmark Data/"

* Table 46
** selection into eshi
qui{
clear
use "Data files/Benchmark.dta"

set more off
gen accepted=0 if (offer==4 | offer==5) & offer_accepted==1
replace accepted=1 if (offer==4 | offer==5) & offer_accepted!=1

gen ESHI_offer=0 if offer==4 | offer==2 
replace ESHI_offer=1 if offer==5 | offer==3

logit accepted i.ESHI_offer##ib3.H wage_offer age age_sq age_cub i.Spouse_status if education==1

table ESHI_offer if education==1, stat(mean accepted )

label var ESHI_offer "ESHI"
label define offer 0 "No ESHI" 1 "ESHI"
label values ESHI_offer offer

label var age_sq "Age squared"
label var age_cub "Age cubed"


logit accepted i.ESHI_offer##ib3.H wage_offer age age_sq age_cub i.married i.education
eststo
	esttab using "${out_tables}/Selection.tex", varwidth(25) nogaps   compress label nobaselevels replace  ///
	nodepvars nonumbers eqlabels(" ") mtitles("Accept Offer"  ) indicate( "Cubic Age = age* age_sq* age_cub* " ) star(* 0.1 ** 0.05 *** 0.01) ///
	 se   b(3) noobs 
	eststo clear
}


* Table 52 
* EMP FT by spouse status
qui{
clear
use "Data files/Benchmark.dta"
sort ID age
* classify emp and non-emp as (NE, PT) and (FT) 
gen EMPLOYMENT_YR1_v1 = 0
gen EMPLOYMENT_YR2_v1 = 0
replace EMPLOYMENT_YR1_v1 = 1 if emp_ft_pt==2
replace EMPLOYMENT_YR2_v1 = 1 if emp_ft_pt[_n+1]==2  & ID==ID[_n+1]

* classify emp and non-emp as (NE, PT, FT NO INS) and (FT WITH INSURANCE) 
* just reclassify those ft without insurance as 0's
gen EMPLOYMENT_YR1_v2 = EMPLOYMENT_YR1_v1
gen EMPLOYMENT_YR2_v2 = EMPLOYMENT_YR2_v1
replace EMPLOYMENT_YR1_v2=0 if EMPLOYMENT_YR1_v2==1 & ESHI==0
replace EMPLOYMENT_YR2_v2=0 if EMPLOYMENT_YR2_v2==1 & ESHI[_n+1]==0  & ID==ID[_n+1]

gen H_Good=0 
replace H_Good=1 if H==3 & H[_n+1]==3 & ID==ID[_n+1]

keep if age>=30 & age<=55

label var EMPLOYMENT_YR1_v1 "Employed FT Last Yr"
label var EMPLOYMENT_YR2_v1 "Employed FT"

label var EMPLOYMENT_YR1_v2 "Employed FT w/ ESHI Last Yr"
label var EMPLOYMENT_YR2_v2 "Employed FT w/ ESHI"

label define emp_v1 0 "No" 1 "Yes"
label values EMPLOYMENT_YR1_v1 emp_v1
label values EMPLOYMENT_YR2_v1 emp_v1
label values EMPLOYMENT_YR1_v2 emp_v1
label values EMPLOYMENT_YR2_v2 emp_v1

table education Spouse_status ,  statistic(mean EMPLOYMENT_YR1_v1) nototals nformat(%5.2f) 
collect title "Fraction Employed FT, ages 30-55, by Marital Status, Model"
collect export "${out_tables}/Mar_LF_Sim.tex", tableonly replace
}


* Table 57 right panel
qui{
clear
use "Data files/Benchmark.dta"

set more off

sort ID age
gen Lagged_ESHI =0 if  ESHI[_n-1]==0 & ID==ID[_n-1] & (offer_accepted==4 | offer_accepted==5) // No ESHI last yr, but  FT this year
replace Lagged_ESHI = 1 if ESHI[_n-1]==1 & ID==ID[_n-1] & (offer_accepted==4 | offer_accepted==5) // ESHI last yr, and PT or FT this year

label define ESHI_last 0 "No ESHI last yr, FT currently" 1 "ESHI last yr, FT currently"
label values Lagged_ESHI ESHI_last
label var Lagged_ESHI "Lagged ESHI and Current Emp"


sort ID age

gen Lagged_emp_ft_pt = 0 if (offer_accepted[_n-1]==1 | offer_accepted[_n-1]==2 | offer_accepted[_n-1]==3)  &  ID==ID[_n-1] & age==age[_n-1]+1
replace Lagged_emp_ft_pt = 1 if (offer_accepted[_n-1]==4 | offer_accepted[_n-1]==5)  &  ID==ID[_n-1] & age==age[_n-1]+1

label var Lagged_emp_ft_pt "Lagged Employment"
label var emp_ft_pt "Employed FT"

label define emp_v1 0 "Not Employed or PT" 1 "Full Time"
label values emp_ft_pt emp_v1
label values Lagged_emp_ft_pt emp_v1

drop emp_ft_pt
gen emp_ft_pt=0 if offer_accepted!=4 &  offer_accepted!=5
replace emp_ft_pt=1 if offer_accepted==4 |  offer_accepted==5

label define EMP_last 0 "Not Employed or PT" 1 "Full Time"
label values emp_ft_pt EMP_last
label var emp_ft_pt "Current Employment"

sort ID age
gen H_lag=H[_n-1] if ID==ID[_n-1]



**** TABLE 57
// table with working FT this year conditional on NE, PT or FT last year
table ( Lagged_emp_ft_pt) (education) if age>=30 & age<=55,  statistic(mean emp_ft_pt) nototals nformat(%5.2f) 
collect title "Fraction Employed FT, ages 30-55, Model"
collect export "${out_tables}/Target_offers_2.tex", tableonly replace
}


** table 58 right panel
qui{
clear
use "Data files/Benchmark.dta"

set more off

sort ID age
gen Lagged_ESHI =0 if  ESHI[_n-1]==0 & ID==ID[_n-1]  // No ESHI last yr, but  FT this year
replace Lagged_ESHI = 1 if ESHI[_n-1]==1 & ID==ID[_n-1]  // ESHI last yr, and PT or FT this year

label define ESHI_last 0 "No ESHI last yr" 1 "ESHI last yry"
label values Lagged_ESHI ESHI_last
label var Lagged_ESHI "Lagged ESHI"


table ( Lagged_ESHI) (education) if age>=30 & age<=55,  statistic(mean ESHI) nototals nformat(%5.2f) 
collect title "Fraction with ESHI, ages 30-55, Model"
collect export "${out_tables}/Target_offers_1_new.tex", tableonly replace
}

* Table 78
* Distribution of work experience at retirement age 
qui{
 clear
use "Data files/Benchmark.dta"
set more off

table  (education) if age>64 ,  statistic( mean SS_income) statistic(mean spouse_income) nototals nformat(%5.2f)  

table () education if age==65,  statistic(fvpercent HC_65) nformat(%5.0f)  // weights make it higher
collect title "Distribution of Experience Groups at Age 65, Model"
collect export "${out_tables}/Experience_65.tex", tableonly replace
}

